package com.yzt.dynamicmodule.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.yzt.p_base.utils.DisplayUtils;
import com.yzt.zhuju.R;

import java.util.List;

/**
 * author : bob
 * date   : 2022/12/7
 * desc   :
 */
public class IndexPageIndicatorView extends LinearLayout {

    /**
     * 指示器的大小（dp）
     */
    private int dotSize = 3;

    /**
     * 指示器间距（dp）
     */
    private int margins = 5;

    /**
     * 存放指示器
     */
    private List<ImageView> indicatorViews = null;

    public IndexPageIndicatorView(Context context) {
        this(context, null);
    }

    public IndexPageIndicatorView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public IndexPageIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {

        setGravity(Gravity.CENTER);
        setOrientation(HORIZONTAL);

        dotSize = DisplayUtils.dip2px(dotSize);
        margins = DisplayUtils.dip2px(margins);
    }

    /**
     * 设置选中页
     *
     * @param selected 页下标，从0开始
     */
    public void setPersonalSelectedPage(int selected) {
        for (int i = 0; i < indicatorViews.size(); i++) {
            if (i == selected) {
                indicatorViews.get(i).setImageResource(R.drawable.shape_index_dot_light_select);
            } else {
                indicatorViews.get(i).setImageResource(R.drawable.shape_index_dot_light_unselect);
            }
        }
    }
}
